package xin.infinite.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xin.infinite.service.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
@Api("用户")
public class UserController {

    @Resource
    private UserService userService;

    @RequestMapping("/register/{email}/{password}/{code}")
    @ApiOperation("用户注册")
    public boolean register(@PathVariable String email,@PathVariable String password,@PathVariable String code){

        return userService.register(email,password,code);
    }

    @RequestMapping("/isRegister/{email}")
    @ApiOperation("用户是否注册注册")
    public boolean isRegister(@PathVariable String email){
        return userService.isRegister(email);
    }

    @RequestMapping("/login/{email}/{password}")
    @ApiOperation("用户登录")
    public String login(@PathVariable String email, @PathVariable String password, HttpServletResponse response){
        return userService.login(email, password, response);
    }

    @RequestMapping("/info/{token}")
    @ApiOperation("根据token查询⽤户登录邮箱")
    public String info(@PathVariable String token){
        return userService.getEmail(token);
    }
}
